package datamining.visualisation;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Properties;

import javax.swing.JButton;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


/** 
 * 创建于 2012-11-21 下午1:27:51
 * 
 * @author xujinghu (jinghuxu@nudt.edu.cn)
 * 
 * Copyright 2012 xujinghu
 * 
 * Lisence: Apache
 */
public class ControlTabbedPanel extends JTabbedPane implements ActionListener,
PropertyChangeListener, ChangeListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private ControlPanel miningControlTab = null;

	private ControlPanel stepMiningControlTab = null;

	private int selectedTabIndex = 0;

	private JButton start = null;

	private Properties props = null;
	
	public ControlTabbedPanel(Properties props){
		super();
		this.props  = props;
		setName("参数设置");
		initTabs();
		initStartButton();
	}

	private void initTabs() {
		miningControlTab = new ControlPanel(props);
		stepMiningControlTab = new ControlPanel(props);

		miningControlTab.addPropertyChangeListener("minimumFrequency", this);
		miningControlTab.addPropertyChangeListener("set sequence", this);
		miningControlTab.addPropertyChangeListener("Algorithm", this);
		miningControlTab.addPropertyChangeListener(UIEvents.start, this);
		this.addPropertyChangeListener("set language properties", miningControlTab);
		this.addPropertyChangeListener("parsed", miningControlTab);
		this.addPropertyChangeListener(props.getProperty("running"), miningControlTab);
		//this.addPropertyChangeListener(UIEvents.start, miningControlTab);
		this.addPropertyChangeListener("step start", miningControlTab);
		this.addPropertyChangeListener("disable", miningControlTab);
		this.addPropertyChangeListener("enable", miningControlTab);

		stepMiningControlTab.addPropertyChangeListener("minimumFrequency", this);
		stepMiningControlTab.addPropertyChangeListener("set sequence", this);
		this.addPropertyChangeListener("set language properties", stepMiningControlTab);
		this.addPropertyChangeListener("parsed", stepMiningControlTab);
		this.addPropertyChangeListener(props.getProperty("running"), stepMiningControlTab);
		this.addPropertyChangeListener("start", stepMiningControlTab);
		this.addPropertyChangeListener("step start", stepMiningControlTab);
		this.addPropertyChangeListener("disable", stepMiningControlTab);
		this.addPropertyChangeListener("enable", stepMiningControlTab);

		addTab(null, miningControlTab);
		addTab(null, stepMiningControlTab);

	}
	
	private void initStartButton() {
	}
	
	@Override
	public void stateChanged(ChangeEvent event) {
		// TODO Auto-generated method stub

		
	}

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		final String propertyName = event.getPropertyName();
		System.err.println(this.getClass().getName()
				+ " property changed " + propertyName);
		
		if (propertyName.equals(UIEvents.start)) {
			firePropertyChange(propertyName, false, true);
		}else if (propertyName.equals(UIEvents.startStep)) {
			firePropertyChange(propertyName, false, true);
		}
	}

	@Override
	public void actionPerformed(ActionEvent event) {
		final String command = event.getActionCommand();
		System.err.println(this.getClass().getName()
				+ "action performed " + command);

	}
	
}
